package pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo1 {
    public static void main(String[] args) {
        //单一线程池
        ExecutorService executorService = Executors.newCachedThreadPool();
        try {
            for(int i = 0 ; i < 100 ; i++){
                executorService.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"该线程已启动！");
                });
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //关闭线程池
            executorService.shutdown();
        }
        //单一线程池
        //Executors.newSingleThreadExecutor();
        //固定线程池
        //Executors.newFixedThreadPool(5);
        //缓存线程池（可伸缩）
        //Executors.newCachedThreadPool();
    }
}
